<?php
/**
 * [YIZHIKEJI System] Copyright (c) 2014 yz929.cn
 * YIZHIKEJI is NOT a free software, it under the license terms, visited http://www.yz929.cn/ for more details.
 */
defined('IN_IA') or exit('Access Denied');
$dos=array('edit','detail');
$do = in_array($do, $dos) ? $do : 'detail';
load()->func('tpl');
if($do == 'detail'){
    if(checksubmit('submit')){
        //moduleid是个数组
        $moduleid = $_GPC['moduleid'];
        foreach($moduleid as $mid){
            if(pdo_get('site_modules',array('mid'=>$mid,'multiid'=>$_W['multiid']))){//数据库中有记录
                pdo_update('site_modules',array('enabled'=>1),array('mid'=>$mid,'multiid'=>$_W['multiid']));
            }else{
                pdo_insert('site_modules',array('mid'=>$mid,'multiid'=>$_W['multiid'],'enabled'=>1,'addtime'=>strtotime(date('Y-m-d'))));
            }
        }
    }
    $multiid = $_W['multiid'];
    $web_uid = $_W['web_uid'];
    $site = pdo_fetch('select title,`describe`,id from '.tablename('site_multi').' where id=:id',array('id'=>$multiid));
    load()->model("module");
    $sql = "SELECT t.*,sm.enabled FROM (SELECT m.mid,m.title,um.deadline from ".tablename('modules')." m,".tablename('users_modules')." um WHERE m.mid=um.mid and um.uid=".$_W['web_uid']." ) t LEFT JOIN (SELECT * from ".tablename('site_modules')." where multiid=".$_W['multiid'].") sm on t.mid = sm.mid";
    //$modules = modules_getValid($_W['web_uid']);
    $modules = pdo_fetchall($sql);

    $articles = pdo_fetchall("select id,title,description from ".tablename("site_article") ."where multiid=".$multiid);

}
template('manage/weizhan');